home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
c01oop.zip
/
CPPWKBK
/
CPPV5-3.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-25
|
884b
|
67 lines
#define HEADER "C++ Problem 5.3 by Rick Conn using Borland C++"
#include <stdio.h>
enum pet_kind {doggy, kitty, neither};
class pet {
pet_kind pk;
public:
pet(pet_kind);
virtual void speak(void);
pet_kind type(void);
};
class dog : public pet {
public:
dog();
void speak(void);
};
class cat : public pet {
public:
cat();
void speak(void);
};
pet::pet(pet_kind kind) {
pk = kind;
}
void pet::speak(void) { }
pet_kind pet::type(void) {
return pk;
}
dog::dog() : pet(doggy) {
// nothing to do
}
void dog::speak(void) {
printf("woof\n");
}
cat::cat() : pet(kitty) {
// nothing to do
}
void cat::speak(void) {
printf("meow\n");
}
void talk (pet *p) {
p -> speak();
}
void main(void)
{
printf("%s\n", HEADER);
dog scotty;
cat fluffy;
talk(&scotty);
talk(&fluffy);
}